import java.util.StringTokenizer;


class P10946_39643 {

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

	public static void main(String[] args) {
		
		int counter = 1;

//		try {
		
			while (true) {
				StringTokenizer st = new StringTokenizer(readLn());
				
				
				int y = Integer.parseInt(st.nextToken());
				int x = Integer.parseInt(st.nextToken());
				
				if (x == 0 && y == 0) break;
				
				System.out.println("Problem " + counter + ":");
				process(x, y);
				counter++;
			}
//		} catch (Exception e) {
////			while (true) {
////				
////			}
//		}
		
	}

	private static void process(int x, int y) {
		char[][] grid = new char[y][x];
		
		for (int k = 0; k < y; k++) {
			String line = readLn();
			
			for (int j = 0; j < x; j++) {
				
				grid[k][j] = line.charAt(j);
				
			}
			
		}
		
		int length = 0;
		char[] letters = new char[10000];
		int[] sizes = new int[10000];
		
		
		
		for (int k = 0; k < grid.length; k++) {
			for (int j = 0; j < grid[k].length; j++) {
				if (grid[k][j] != '.') {
					letters[length] = grid[k][j];
					sizes[length] = flood(grid[k][j], grid, k, j);
					length++;
					
//					print(grid);
				}
			}
		}
		
		sort(letters, sizes, 0, length-1);
		
		for (int k = length - 1; k >= 0; k--) {
			System.out.println(letters[k] + " " + sizes[k]);
		}
		
	}
	
	static void print(char[][] grid) {
		System.out.println("-=-=-=");
		for (int k = 0; k < grid.length; k++) {
			for (int j = 0; j < grid[0].length; j++) {
				System.out.print(grid[k][j]);
			}
			System.out.println();
		}
		System.out.println("=-=-=-=");
	}
	
	private static int flood(char t, char[][] grid, int k, int j) {
		int value = 0;
		
		if (grid[k][j] == t) {
			grid[k][j] = '.';
			value++;
		 
		
			if (k + 1 < grid.length) value += flood(t, grid, k+1, j);
			if (j + 1 < grid[k].length) value += flood(t, grid, k, j+1);
			
			if (k - 1 >= 0) value += flood(t, grid, k-1, j);
			if (j - 1 >= 0) value += flood(t, grid, k, j-1);
			
//			if (k + 1 < n && j + 1 < m) value += flood(t, grid, k+1, j+1, n, m);
//			if (k - 1 >= 0 && j - 1 >= 0) value += flood(t, grid, k-1, j-1, n, m);
//			
//			if (k + 1 < n && j - 1 >= 0) value += flood(t, grid, k+1, j-1, n, m);
//			if (k - 1 >= 0 && j + 1 < m) value += flood(t, grid, k-1, j+1, n, m);
			
			return value;
		
		} else {
			
			return value;
		}
	}
	
    static void sort(char[] letters, int[] sizes, int lo0, int hi0) {
		int lo = lo0;
		int hi = hi0;
		int mid;
		char midC;
		if (hi0 > lo0) {

			mid = sizes[(lo0 + hi0) / 2];
			midC = letters[(lo0 + hi0) / 2];

			while (lo <= hi) {
				while ((lo < hi0) && ((compareTo(sizes[lo], mid, letters[lo], midC) > 0)))
					++lo;

				while ((hi > lo0) && ((compareTo(sizes[hi], mid, letters[hi], midC) < 0 )))
					--hi;

				if (lo <= hi) {
					swap(letters, sizes, lo, hi);

					++lo;
					--hi;
				}
			}

			if (lo0 < hi)
				sort(letters, sizes, lo0, hi);

			if (lo < hi0)
				sort(letters, sizes, lo, hi0);

		}
	}


	private static int compareTo(int i, int j, char a, char b) {
		if (i != j) {
			return j - i;
		}
		
		return new Character(a).compareTo(new Character(b));
		
	}

	private static void swap(char[] letters, int[] teams, int lo, int hi) {
		int aux = teams[lo];
		teams[lo] = teams[hi];
		teams[hi] = aux;
		
		char auxC = letters[lo];
		letters[lo] = letters[hi];
		letters[hi] = auxC;
		
	}

	
}
